using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace ScytheEngine
{
    public class ShaderManager
    {
        #region Data Members

        private static Dictionary<string,Shader> m_Shaders = new Dictionary<string,Shader>();	// our shaders library
		private static GraphicsDevice m_GfxDev;	// keeps a reference to the graphics device so it can get a hold of BasicEffect

        #endregion

		#region Methods

		public static void Initialize(GraphicsDevice gfxDev)
		{
			m_GfxDev = gfxDev;
		}

		public static void AddShader(Shader newShader, string shaderLabel)
        {
			m_Shaders.Add( shaderLabel, newShader );
        }

        public static Shader GetShader(string shaderLabel)
        {
            if ( shaderLabel != null && m_Shaders.ContainsKey(shaderLabel))
            {
                return m_Shaders[shaderLabel];
            }
            else
            {
				return DefaultShader();
            }
        }

        public static void LoadContent(ContentManager loader)
        {
            foreach ( Shader shader in m_Shaders.Values)
            {
                shader.LoadContent(loader);
            }
        }

        public static Shader DefaultShader()
        {
			Debug.Assert( m_GfxDev != null, "Shader manager has not been initialized!" );
            Shader defaultShader = new Shader(String.Empty);
            defaultShader.Effect = new BasicEffect(m_GfxDev, new EffectPool());
            return defaultShader;
        }

        #endregion
    }
}
